package com.zjl.Kafka.第04章_分布式扩展;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.connector.kafka.source.KafkaSource;
import org.apache.flink.connector.kafka.source.enumerator.initializer.OffsetsInitializer;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.kafka.clients.consumer.KafkaConsumer;

/**
 * ClassName: G_Filnk同步计算引擎
 * Package: com.zjl.Kafka.第04章_分布式扩展
 * Description:
 *
 * @Author 张蛟龙
 * @Create 2024/9/11 20:49
 * @Version 1.0
 */
public class G_Filnk同步计算引擎 {
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        KafkaSource<String> kafkaSource = KafkaSource.<String>builder()
                .setBootstrapServers("82.157.71.243:9092")//地址
                .setTopics("test")//主题名
                .setGroupId("x1")//消费者组名
                .setStartingOffsets(OffsetsInitializer.latest())//获取偏移量的方式  默认
                .setValueOnlyDeserializer(new SimpleStringSchema())//反序列化
                .build();
        DataStreamSource<String> stringDataStreamSource = env.fromSource(kafkaSource,
                WatermarkStrategy.noWatermarks(),
                "kafka-source");
        stringDataStreamSource.print("kafka");
        env.execute();
    }
}
